<template>
  <div v-if="createAuth">
    <page-header
      :title="$route.query.id ? $t('m.branch_Edit') : $t('m.branch_Create')"
      is-emphasize
    >
      <el-button @click="submit()">{{ $t('m.save') }}</el-button>
    </page-header>
    <div class="detail_div container">
      <div class="detail_left">
        <div class="detail_left_div" style=" padding-bottom: 20px;">
          <el-form
            label-position="top"
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm1"
            ><div class="create_title">{{ $t('m.Offer_Information') }}</div>
            <el-form-item :label="$t('m.Discount_type') + '*'">
              <el-radio-group
                v-model="ruleForm.deductionType"
                size="medium"
                @input="changeDeductionType"
              >
                <el-radio-button :label="1">{{
                  $t('m.system_FreeDuration')
                }}</el-radio-button>
                <el-radio-button :label="2">{{
                  $t('m.couponAmount')
                }}</el-radio-button>
                <el-radio-button :label="3">{{
                  $t('m.Rent_discount')
                }}</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <div class="create_title2">
              {{
                ruleForm.deductionType == 1
                  ? $t('m.system_FreeDuration')
                  : ruleForm.deductionType == 2
                  ? $t('m.couponAmount')
                  : $t('m.Rent_discount')
              }}*
            </div>
            <el-form-item
              prop="deduction.type1FreeDurationVal"
              v-if="ruleForm.deductionType == 1"
              key="type1FreeDurationVal"
            >
              <div class="el_form_item_div">
                <el-input
                  v-model="ruleForm.deduction.type1FreeDurationVal"
                  @input="changeType1FreeDurationVal"
                  :placeholder="$t('m.Please_enter')"
                  clearable
                  maxlength="3"
                ></el-input>
                <div
                  class="el_item_div "
                  @click="ruleForm.deduction.type1FreeDurationUnit = 1"
                  :class="{
                    active_div: ruleForm.deduction.type1FreeDurationUnit == 1
                  }"
                >
                  {{ $t('m.minute') }}
                </div>
                <div
                  class="el_item_div"
                  @click="ruleForm.deduction.type1FreeDurationUnit = 2"
                  :class="{
                    active_div: ruleForm.deduction.type1FreeDurationUnit == 2
                  }"
                >
                  {{ $t('m.hour2') }}
                </div>
              </div>
            </el-form-item>
            <el-form-item
              :label="$t('m.Term_of_use') + '*'"
              v-if="ruleForm.deductionType == 1"
              :style="
                ruleForm.deduction.type1DiscountCondition == 1
                  ? 'margin-bottom:0;'
                  : ''
              "
            >
              <el-radio-group
                v-model="ruleForm.deduction.type1DiscountCondition"
              >
                <el-radio :label="1">{{
                  $t('m.Minimum_rental_duration')
                }}</el-radio>
                <el-radio :label="2">{{ $t('m.Unlimit') }}</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              prop="deduction.type1MinRentalTime"
              key="type1MinRentalTime"
              v-if="
                ruleForm.deductionType == 1 &&
                  ruleForm.deduction.type1DiscountCondition == 1
              "
            >
              <div class="el_form_item_div">
                <el-input
                  v-model="ruleForm.deduction.type1MinRentalTime"
                  @input="changeType1MinRentalTime"
                  :placeholder="$t('m.Please_enter')"
                  clearable
                  maxlength="3"
                ></el-input>
                <div
                  class="el_item_div "
                  @click="ruleForm.deduction.type1MinRentalTimeUnit = 1"
                  :class="{
                    active_div: ruleForm.deduction.type1MinRentalTimeUnit == 1
                  }"
                >
                  {{ $t('m.minute') }}
                </div>
                <div
                  class="el_item_div"
                  @click="ruleForm.deduction.type1MinRentalTimeUnit = 2"
                  :class="{
                    active_div: ruleForm.deduction.type1MinRentalTimeUnit == 2
                  }"
                >
                  {{ $t('m.hour2') }}
                </div>
              </div>
            </el-form-item>
            <el-form-item
              v-if="ruleForm.deductionType == 2"
              prop="deduction.type2DiscountAmount"
              key="type2DiscountAmount"
            >
              <div id="box" class="currency">{{ $currency.symbol }}</div>
              <el-input
                v-model="ruleForm.deduction.type2DiscountAmount"
                @input="changeType2DiscountAmount"
                :placeholder="$t('m.Please_enter')"
                clearable
                maxlength="7"
                class="currency_input"
                :style="widthStyle"
              ></el-input>
            </el-form-item>
            <el-form-item
              v-if="ruleForm.deductionType == 3"
              prop="deduction.type3DiscountAmount"
              key="type3DiscountAmount"
            >
              <el-input
                v-model="ruleForm.deduction.type3DiscountAmount"
                @input="changeType3DiscountAmount"
                :placeholder="$t('m.Please_enter')"
                clearable
                maxlength="3"
                ><template slot="append">%</template></el-input
              >
            </el-form-item>
            <el-form-item
              :label="$t('m.Term_of_use') + '*'"
              v-if="ruleForm.deductionType == 2"
              style="margin-bottom:0;"
            >
              <el-radio-group
                v-model="ruleForm.deduction.type2DiscountCondition"
                @input="changeDeductionType2"
              >
                <el-radio :label="1">{{
                  $t('m.Minimum_rental_amount')
                }}</el-radio>
                <el-radio :label="2">{{ $t('m.Unlimit') }}</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              :label="$t('m.Term_of_use') + '*'"
              v-if="ruleForm.deductionType == 3"
              style="margin-bottom:0;"
            >
              <el-radio-group
                v-model="ruleForm.deduction.type3DiscountCondition"
                @input="changeDeductionType3"
              >
                <el-radio :label="1">{{
                  $t('m.Minimum_rental_amount')
                }}</el-radio>
                <el-radio :label="2">{{ $t('m.Unlimit') }}</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              v-if="
                ruleForm.deductionType == 2 &&
                  ruleForm.deduction.type2DiscountCondition == 1
              "
              prop="deduction.type2MinRentalAmount"
              key="type2MinRentalAmount"
            >
              <div id="box" class="currency">{{ $currency.symbol }}</div>
              <el-input
                v-model="ruleForm.deduction.type2MinRentalAmount"
                @input="changeType2MinRentalAmount"
                :placeholder="$t('m.Please_enter')"
                clearable
                maxlength="7"
                class="currency_input"
                :style="widthStyle"
              ></el-input>
            </el-form-item>
            <el-form-item
              v-if="
                ruleForm.deductionType == 3 &&
                  ruleForm.deduction.type3DiscountCondition == 1
              "
              prop="deduction.type3MinRentalAmount"
              key="type3MinRentalAmount"
            >
              <div id="box" class="currency">{{ $currency.symbol }}</div>
              <el-input
                v-model="ruleForm.deduction.type3MinRentalAmount"
                @input="changeType3MinRentalAmount"
                :placeholder="$t('m.Please_enter')"
                clearable
                maxlength="7"
                class="currency_input"
                :style="widthStyle"
              ></el-input>
            </el-form-item>
            <div class="create_title">{{ $t('m.Expiry_time') }}*</div>
            <el-form-item
              :style="ruleForm.expiredType == 1 ? 'margin-bottom:0;' : ''"
            >
              <el-radio-group v-model="ruleForm.expiredType">
                <el-radio :label="1">{{ $t('m.Validity_period') }}</el-radio>
                <el-radio :label="2">{{ $t('m.Permanent2') }}</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              v-if="ruleForm.expiredType == 1"
              prop="times"
              key="times"
            >
              <el-date-picker
                v-model="ruleForm.times"
                @input="choiceTimes"
                style="width:390px;"
                :picker-options="pickerBeginDateBefore"
                type="daterange"
                :default-time="['00:00:00', '23:59:59']"
                value-format="timestamp"
                range-separator="~"
                :start-placeholder="$t('m.start_date')"
                :end-placeholder="$t('m.end_date')"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item :label="$t('m.status') + '*'">
              <el-radio-group v-model="ruleForm.state">
                <el-radio :label="1">{{ $t('m.Online_coupon') }}</el-radio>
                <el-radio :label="0">{{ $t('m.Offline_coupon') }}</el-radio>
              </el-radio-group>
            </el-form-item>
            <div class="create_title">{{ $t('m.Redemption_information') }}</div>
            <div class="create_title2">{{ $t('m.select_coupon_type') }}*</div>
            <el-form-item prop="exchangePoint">
              <el-input
                v-model="ruleForm.exchangePoint"
                @input="changeExchangePoint"
                :placeholder="$t('m.Please_enter')"
                clearable
                maxlength="3"
              ></el-input
            ></el-form-item>
            <div class="create_title2">
              {{ $t('m.Validated_period_after_redemption') }}*
            </div>
            <el-form-item prop="exchangeEffectiveDays">
              <el-input
                v-model="ruleForm.exchangeEffectiveDays"
                @input="changeExchangeEffectiveDays"
                :placeholder="$t('m.Please_enter')"
                clearable
                maxlength="3"
              ></el-input>
            </el-form-item>
            <div class="create_title">{{ $t('m.Order_else') }}</div>
            <el-form-item :label="$t('m.Usage_coupon') + '*'">
              <el-radio-group v-model="ruleForm.usageMethod">
                <el-radio :label="1">
                  {{ $t('m.Auto_deduct') }}
                  <el-tooltip
                    class="item"
                    effect="dark"
                    :content="$t('m.couponCMStep2Hint')"
                    placement="top-start"
                  >
                    <img
                      src="@/assets/imgs/ic_mark@2x.png"
                      style="width:16px;height:16px;vertical-align:middle;bottom: 2px;position: relative;"
                    />
                  </el-tooltip>
                </el-radio>
                <el-radio :label="2">{{ $t('m.Manually_choose') }}</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              :label="$t('m.Inventory') + '*'"
              style="margin-bottom:0;"
            >
              <el-radio-group v-model="ruleForm.stockType">
                <el-radio :label="1">{{ $t('m.Set_quantity') }}</el-radio>
                <el-radio :label="2">{{ $t('m.Unlimit') }}</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              prop="stockNum"
              v-if="ruleForm.stockType == 1"
              key="stockNum"
            >
              <el-input
                v-model="ruleForm.stockNum"
                @input="changeStockNum"
                :placeholder="$t('m.Please_enter')"
                clearable
                maxlength="4"
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="detail_right">
        <div class="detail_left_div" style=" padding-bottom: 20px;">
          <el-form
            label-position="top"
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm2"
          >
            <div class="create_title2">{{ $t('m.Available_merchants') }}*</div>
            <el-form-item
              :style="ruleForm.applyType == 1 ? 'margin-bottom:0;' : ''"
            >
              <el-radio-group
                v-model="ruleForm.applyType"
                @input="changeApplyType"
              >
                <el-radio :label="0">{{ $t('m.All_merchants') }}</el-radio>
                <el-radio :label="1">{{
                  $t('m.Designated_locations')
                }}</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              v-if="ruleForm.applyType == 1"
              prop="merchantIdList"
              key="merchantIdList"
            >
              <el-select
                v-model="ruleForm.merchantIdList"
                multiple
                filterable
                class="el_select_input"
                :placeholder="$t('m.pleaseChoose')"
                style="width:100%;"
              >
                <el-option
                  v-for="item in optionsMerchant"
                  :key="'' + item.id"
                  :label="item.branchName"
                  :value="'' + item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <div class="create_title2">
              {{ $t('m.Preferential_amount_order_profit') }}*
            </div>
            <el-form-item style="margin-bottom:0;">
              <el-radio-group v-model="ruleForm.undertaker">
                <el-radio :label="0"
                  >{{ $t('m.Station_List_Distribution_Yes') }}
                </el-radio>
                <el-radio :label="1"
                  >{{ $t('m.Station_List_Distribution_No') }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
            <div class="create_title2">
              {{ $t('m.After_using_the_coupon') }}*
            </div>
            <el-form-item style="margin-bottom:0;">
              <el-radio-group v-model="ruleForm.minPaymentDeal">
                <el-radio :label="0">{{ $t('m.platformDiscount') }}</el-radio>
                <el-radio :label="1">{{
                  $t('m.UserPays_minimum_transaction_amount')
                }}</el-radio>
              </el-radio-group>
            </el-form-item>
            <div style="color:#646B80;">
              {{
                $t('m.UserPays_minimum_transaction_amount_hint').replace(
                  'xxx',
                  $format.amountFormat(0.5)
                )
              }}
            </div>
          </el-form>
        </div>
        <div class="detail_left_div" style=" padding-bottom: 20px;">
          <el-form
            label-position="top"
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm3"
          >
            <div class="create_title">{{ $t('m.Instructions_for_use') }}</div>
            <div class="create_title2">
              Tiếng Việt*
            </div>
            <el-form-item prop="description.vi">
              <el-input
                v-model="ruleForm.description.vi"
                :placeholder="$t('m.Please_enter')"
                :autosize="{ minRows: 4, maxRows: 6 }"
                type="textarea"
                clearable
                maxlength="200"
                show-word-limit
              ></el-input>
            </el-form-item>
            <div class="create_title2">简体中文*</div>
            <el-form-item prop="description.zh">
              <el-input
                v-model="ruleForm.description.zh"
                :placeholder="$t('m.Please_enter')"
                :autosize="{ minRows: 4, maxRows: 6 }"
                type="textarea"
                clearable
                maxlength="200"
                show-word-limit
              ></el-input>
            </el-form-item>
            <div class="create_title2">English*</div>
            <el-form-item prop="description.en">
              <el-input
                v-model="ruleForm.description.en"
                :placeholder="$t('m.Please_enter')"
                :autosize="{ minRows: 4, maxRows: 6 }"
                type="textarea"
                clearable
                maxlength="200"
                show-word-limit
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      pickerBeginDateBefore: {
        disabledDate (time) {
          return time.getTime() < Date.now() - 24 * 60 * 60 * 1000
        }
      },
      ruleForm: {
        applyType: 0, //适用类型：0.所有商家 1.指定商家
        deduction: {
          type: 1, //	抵扣类型：1-免费时长 2-优惠金额 3-金额折扣
          type1DiscountCondition: 1, //	type1-优惠条件：1-最少租用时间 2-不限制
          type1FreeDurationUnit: 1, //	type1-免费时长单位：1-分钟 2-小时
          type1FreeDurationVal: '', //	type1-免费时长值
          type1MinRentalTime: '', //	type1-最少租用时间
          type1MinRentalTimeUnit: 1, //	type1-最少租用时间单位：1-分钟 2-小时
          type2DiscountAmount: '', //	type2-优惠金额
          type2DiscountCondition: 1, //	type2-优惠条件：1-最低租金金额 2-不限制
          type2MinRentalAmount: '', //	type2-最低租金金额
          type3DiscountAmount: '', //	type3-租金折扣
          type3DiscountCondition: 1, //	type3-优惠条件：1-最低租金金额 2-不限制
          type3MinRentalAmount: '' //	type3-最低租金金额
        },
        deductionType: 1, // 抵扣类型：1-免费时长 2-优惠金额 3-金额折扣
        description: {
          de: '', //	德语
          en: '', //	英文
          fr: '', //	法语
          vi: '', //	
          it: '', //	
          vi: '', //	越南语
          zh: '' //	中文
        },
        endTime: '', // 上架结束时间
        exchangeEffectiveDays: '', //	兑换生效天数
        exchangeLimit: '', //	兑换数量(优惠码数量)
        exchangePoint: '', //	兑换积分
        expiredType: 1, //	到期时间类型：1.有效期 2.永不过期
        id: '',
        image: '', //	优惠券样式图片地址
        merchantIdList: null, //	商家id集合，为null表示全平台
        minPaymentDeal: 0, //	最低支付金额处理：0-优惠 1-支付
        platformId: '', //	平台id
        startTime: '', //	起始时间
        state: 1, //	状态：1-上架 0-下架
        stockNum: '', //	库存数
        stockType: 1, //	库存类型：1.设置数量 2.无限制
        times: '', //	时间段
        title: '', //	优惠券名称
        undertaker: 0, //	优惠金额承担：0-品牌 1-商家
        updateTime: '',
        usageLimit: '', //	每人使用限制
        usageMethod: 1 //	使用方式：1.自动扣除 2.手动选择
      },
      rules: {
        'deduction.type1FreeDurationVal': [
          {
            required: true,
            message: this.$t('m.Enter_free_duration'),
            trigger: 'blur'
          }
        ],
        'deduction.type1MinRentalTime': [
          {
            required: true,
            message: this.$t('m.Please_enter_minimum_rental_duration'),
            trigger: 'blur'
          }
        ],
        'deduction.type2DiscountAmount': [
          {
            required: true,
            message: this.$t('m.Please_enter_discount_amount'),
            trigger: 'blur'
          }
        ],
        'deduction.type3DiscountAmount': [
          {
            required: true,
            message: this.$t('m.enter_rental_discount'),
            trigger: 'blur'
          }
        ],
        'deduction.type2MinRentalAmount': [
          {
            required: true,
            message: this.$t('m.Please_enter_minimum_rental_amount'),
            trigger: 'blur'
          }
        ],
        'deduction.type3MinRentalAmount': [
          {
            required: true,
            message: this.$t('m.Please_enter_minimum_rental_amount'),
            trigger: 'blur'
          }
        ],
        times: [
          {
            required: true,
            message: this.$t('m.Please_set_expiry_date'),
            trigger: 'change'
          }
        ],
        exchangePoint: [
          {
            required: true,
            message: this.$t('m.Please_enter_redeem_points'),
            trigger: 'blur'
          }
        ],
        exchangeEffectiveDays: [
          {
            required: true,
            message: this.$t('m.Please_enter_validation_days'),
            trigger: 'blur'
          }
        ],
        stockNum: [
          {
            required: true,
            message: this.$t('m.enter_Inventory'),
            trigger: 'blur'
          }
        ],
        merchantIdList: [
          {
            required: true,
            message: this.$t('m.Select_merchant'),
            trigger: 'change'
          }
        ],
        'description.vi': [
          {
            required: true,
            message: this.$t('m.Please_enter_instructions_for_use'),
            trigger: 'blur'
          }
        ],
        'description.en': [
          {
            required: true,
            message: this.$t('m.Please_enter_instructions_for_use'),
            trigger: 'blur'
          }
        ],
        'description.zh': [
          {
            required: true,
            message: this.$t('m.Please_enter_instructions_for_use'),
            trigger: 'blur'
          }
        ]
      },
      currencyWidth: '',
      optionsMerchant: [], // 商家
      createAuth: this.permissionsId(192)
    }
  },
  computed: {
    widthStyle () {
      return {
        '--currencyWidth': this.currencyWidth
      }
    }
  },
  created () {
    if (!this.createAuth) {
      return
    }
    this.getBranchListBox()
    if (this.$route.query.id) {
      this.getDetail()
    }
  },
  mounted () {},
  methods: {
    //获取货币宽度
    getWidth () {
      this.$nextTick(() => {
        let box = document.getElementById('box')
        this.currencyWidth = box.clientWidth + 14 + 'px'
      })
    },
    // 获取编辑信息
    getDetail () {
      this.$openLoading()
      this.$api.coupon.getEditDetail(this.$route.query.id).then(res => {
        this.$closeLoading()
        if (this.$ok(res)) {
          this.ruleForm = res.data
          if (
            this.ruleForm.deductionType == 2 ||
            (this.ruleForm.deductionType == 3 &&
              this.ruleForm.deduction.type3DiscountCondition == 1)
          ) {
            this.getWidth()
          }          
          if (res.data.applyType == 0) {
            this.ruleForm.merchantIdList = ''
          } else {
            this.ruleForm.merchantIdList = this.ruleForm.merchantIdList.split(
              ','
            )
          }
          if (res.data.expiredType == 2) {
            this.$set(this.ruleForm, 'times', '')
          } else {
            this.$set(this.ruleForm, 'times', [
              res.data.startTime,
              res.data.endTime
            ])
          }
          // console.log(this.ruleForm)
        }
      })
    },

    // 选择搜索日期
    choiceTimes (value) {
      // console.log(value)
      if (value) {
        this.ruleForm.startTime = this.ruleForm.times[0]
        this.ruleForm.endTime = this.ruleForm.times[1]
      } else {
        this.ruleForm.startTime = ''
        this.ruleForm.endTime = ''
      }
      this.$forceUpdate()
    },

    // 获取商家下拉数据
    getBranchListBox () {
      this.$api.merchant.getListBox().then(res => {
        if (this.$ok(res)) {
          this.optionsMerchant = res.data
        }
      })
    },

    //选择优惠类型
    changeDeductionType () {
      this.ruleForm.deduction.type = this.ruleForm.deductionType
      if (
        this.ruleForm.deductionType == 2 ||
        (this.ruleForm.deductionType == 3 &&
          this.ruleForm.deduction.type3DiscountCondition == 1)
      ) {
        this.getWidth()
      }  
      // console.log(this.ruleForm.deductionType)
      this.$refs['ruleForm1'].clearValidate(['deduction.type1FreeDurationVal'])
      this.$refs['ruleForm1'].clearValidate(['deduction.type1MinRentalTime'])
      this.$refs['ruleForm1'].clearValidate(['deduction.type2DiscountAmount'])
      this.$refs['ruleForm1'].clearValidate(['deduction.type2MinRentalAmount'])
      this.$refs['ruleForm1'].clearValidate(['deduction.type3DiscountAmount'])
      this.$refs['ruleForm1'].clearValidate(['deduction.type3MinRentalAmount'])
    },

    //免费时长-限制输入
    changeType1FreeDurationVal (val) {
      this.ruleForm.deduction.type1FreeDurationVal = this.$check.noZero(val)
    },
    //优惠条件-时长限制输入
    changeType1MinRentalTime (val) {
      this.ruleForm.deduction.type1MinRentalTime = this.$check.noZero(val)
    },
    //优惠金额-优惠金额限制输入
    changeType2DiscountAmount (val) {
      this.ruleForm.deduction.type2DiscountAmount = this.$check.noZero(val)
    },
    //租金折扣-折扣限制输入
    changeType3DiscountAmount (val) {
      this.ruleForm.deduction.type3DiscountAmount = this.$check.noZero(val)
      if (this.ruleForm.deduction.type3DiscountAmount > 100) {
        this.ruleForm.deduction.type3DiscountAmount = 100
      }
    },
    //优惠金额-优惠条件限制输入
    changeType2MinRentalAmount (val) {
      this.ruleForm.deduction.type2MinRentalAmount = this.$check.noZero(val)
    },
    //租金折扣-优惠条件限制输入
    changeType3MinRentalAmount (val) {
      this.ruleForm.deduction.type3MinRentalAmount = this.$check.noZero(val)
    },
    //兑换积分值限制输入
    changeExchangePoint (val) {
      this.ruleForm.exchangePoint = this.$check.noZero(val)
    },
    //兑换后的生效天数限制输入
    changeExchangeEffectiveDays (val) {
      this.ruleForm.exchangeEffectiveDays = this.$check.noZero(val)
    },
    //库存限制输入
    changeStockNum (val) {
      this.ruleForm.stockNum = this.$check.noZero(val)
    },

    //选择商家
    changeApplyType () {
      this.$nextTick(() => {
        this.$refs['ruleForm2'].clearValidate(['merchantIdList'])
      })
    },

    changeDeductionType2 () {
      if (this.ruleForm.deduction.type2DiscountCondition == 1) {
        this.getWidth()
      }
    },
    changeDeductionType3 () {
      if (this.ruleForm.deduction.type3DiscountCondition == 1) {
        this.getWidth()
      }
    },    

    // 创建/编辑
    async submit () {
      try {
        await Promise.all([
          this.$refs.ruleForm1.validate(),
          this.$refs.ruleForm2.validate(),
          this.$refs.ruleForm3.validate()
        ])
        this.$openLoading()
        let params = { ...this.ruleForm }
        delete params.times
        if (this.ruleForm.deductionType == 1) {
          params.deduction.type2DiscountAmount = ''
          params.deduction.type2MinRentalAmount = ''
          params.deduction.type3DiscountAmount = ''
          params.deduction.type3MinRentalAmount = ''
        } else if (this.ruleForm.deductionType == 2) {
          params.deduction.type1FreeDurationVal = ''
          params.deduction.type1MinRentalTime = ''
          params.deduction.type3DiscountAmount = ''
          params.deduction.type3MinRentalAmount = ''
        } else {
          params.deduction.type1FreeDurationVal = ''
          params.deduction.type1MinRentalTime = ''
          params.deduction.type2DiscountAmount = ''
          params.deduction.type2MinRentalAmount = ''
        }
        if (this.ruleForm.expiredType == 2) {
          params.endTime = ''
          params.startTime = ''
        }
        if (this.ruleForm.stockType == 2) {
          params.stockNum = ''
        }
        if (this.ruleForm.applyType == 0) {
          params.merchantIdList = null
        } else {
          params.merchantIdList = params.merchantIdList.toString()
        }
        // console.log(this.ruleForm, params)
        this.$api.coupon.addCoupon(params).then(res => {
          this.$closeLoading()
          if (this.$ok(res)) {
            if (!params.id) {
              this.remPageNum()
            }
            this.$router.go(-1)
            this.$message.success(res.message)
          } else {
            this.$message.error(res.message)
          }
        })
      } catch (error) {
        // 验证失败
        // console.log('error submit !')
        return
      }
    }
  }
}
</script>

<style scoped lang="scss">
.currency {
  position: absolute;
  z-index: 6;
  top: 50%;
  left: 10px;
  color: #39404d;
  font-size: 14px;
  font-weight: 500;
}
.currency_input {
  ::v-deep .el-input__inner {
    padding-left: var(--currencyWidth) !important;
  }
}
.el-form-item.is-error .el-input__inner,
.el-form-item.is-error .el-input__inner:focus,
.el-form-item.is-error .el-textarea__inner,
.el-form-item.is-error .el-textarea__inner:focus {
  border-color: #fd5849 !important;
}
.el_select_input {
  ::v-deep .el-input__inner {
    // height: 100% !important;
    max-height: 1500px !important;
    min-height: 36px !important;
  }
}
</style>
